package com.example.app.controller;

import com.example.app.service.DeepSeekService;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.Map;

@RestController
@RequestMapping("/api/deepseek")
public class DeepSeekController {

    private final DeepSeekService deepSeekService;

    public DeepSeekController(DeepSeekService deepSeekService) {
        this.deepSeekService = deepSeekService;
    }

//    @PostMapping("/answer")
//    public Mono<String> answerQuestion(
//            @RequestBody String message,
//            @RequestParam(defaultValue = "true") boolean withRAG
//    ) {
//        return deepSeekService.answerQuestion(message, withRAG);
//    }
    @PostMapping("/answer")
    public Mono<String> answerQuestion(
            @RequestParam Long userId,
            @RequestBody String message,
            @RequestParam(defaultValue = "true") boolean withRAG
    ) {
        String fullPrompt = deepSeekService.buildPrompt(userId, message);
        return deepSeekService.answerQuestionLORA(fullPrompt, withRAG);
    }


    @PostMapping("/answer/evaluate")
    public Mono<String> answerQuestionWithEvaluation(
            @RequestBody Map<String, String> requestBody,
            @RequestParam(defaultValue = "true") boolean withRAG
    ) {
        return deepSeekService.answerQuestionWithEvaluation(
                requestBody.get("message1"),
                requestBody.get("message2"),
                withRAG
        );
    }
}